package com.example.myapplication;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class FirstActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.first_layout);
        // 关联用户名、密码和登录、返回按钮
        final EditText userName = (EditText) this.findViewById(R.id.etName);
        final EditText passWord = (EditText) this.findViewById(R.id.etPwd);
        Button loginButton = (Button) this.findViewById(R.id.LoginButton);
        Button backButton = (Button) this.findViewById(R.id.BackButton);
        // 登录按钮监听器
        loginButton.setOnClickListener(
                new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // 获取用户名和密码
                        String strUserName = userName.getText().toString().trim();
                        String strPassWord = passWord.getText().toString().trim();
                        // 判断如果用户名为"姓名"密码为"学号"则登录成功
                        if (strUserName.equals("谢凡") && strPassWord.equals("2201280136")) {
                            Toast.makeText(FirstActivity.this, "登录成功！", Toast.LENGTH_SHORT).show();
//                            切换Activity
                            Intent intent=new Intent();
                            intent.setClass(FirstActivity.this, SecondActivity.class);
                            startActivity(intent);
                        } else {
                            Toast.makeText(FirstActivity.this, "输入的用户名或密码不正确，请重新输入!", Toast.LENGTH_SHORT).show();
                        }
                    }
                }
        );

//        返回按钮监听器
        backButton.setOnClickListener(
                new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(FirstActivity.this, "回到启动器...", Toast.LENGTH_SHORT).show();
                    }
                }
        );
    }
}